//package com.sskj.llg_data;
//
//import com.alibaba.fastjson.JSON;
//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
//import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
//import com.shslgc.common.core.constant.ErrorCodeEnum;
//import com.shslgc.common.core.object.ResponseResult;
//import com.shslgc.common.core.util.MyModelUtil;
//import com.shslgc.common.sequence.wrapper.IdGeneratorWrapper;
//import com.shslgc.dataapi.vo.LlgDataDikeStructureVO;
//import com.shslgc.dataservice.dao.LlgDataDikeStructureMapper;
//import com.shslgc.dataservice.model.LlgDataDikeStructure;
//import com.shslgc.dataservice.service.LlgDataDikeStructureService;
//import com.shslgc.dataservice.util.BeanCopy;
//import com.shslgc.dataservice.util.IotMyModelUtil;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.commons.collections4.CollectionUtils;
//import org.apache.commons.lang3.StringUtils;
//import org.apache.ibatis.annotations.Param;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Service;
//import org.springframework.transaction.annotation.Transactional;
//
//import javax.annotation.Resource;
//import java.util.ArrayList;
//import java.util.List;
//import java.util.stream.Collectors;
//
//@Slf4j
//@Service
//public class LlgDataDikeStructureServiceImpl extends ServiceImpl<LlgDataDikeStructureMapper, LlgDataDikeStructure> implements LlgDataDikeStructureService {
//
//    @Resource
//    private LlgDataDikeStructureMapper llgDataDikeStructureMapper;
//    @Autowired
//    private IdGeneratorWrapper idGenerator;
//
//    /**
//     * 查询表llg_data_dike_structure所有信息
//     */
//    @Override
//    public List<LlgDataDikeStructure> findAll() {
//        return llgDataDikeStructureMapper.findAll();
//    }
//
//    /**
//     * 根据主键fId查询表llg_data_dike_structure信息
//     *
//     * @param fId
//     */
//    @Override
//    public LlgDataDikeStructure findById(@Param("fId") String fId) {
//        return llgDataDikeStructureMapper.findById(fId);
//    }
//
//    /**
//     * 根据条件查询表llg_data_dike_structure信息
//     *
//     * @param llgDataDikeStructure
//     */
//    @Override
//    public List<LlgDataDikeStructure> findByCondition(LlgDataDikeStructure llgDataDikeStructure) {
//        return llgDataDikeStructureMapper.findByCondition(llgDataDikeStructure);
//    }
//
//    /**
//     * 分页查询表llg_data_dike_structure信息
//     *
//     * @param llgDataDikeStructure
//     */
//    @Override
//    public List<LlgDataDikeStructure> findListByPage(LlgDataDikeStructure llgDataDikeStructure, String orderBy) {
//        return llgDataDikeStructureMapper.findListByPage(llgDataDikeStructure, orderBy);
//    }
//
//    /**
//     * 根据主键fId查询表llg_data_dike_structure信息
//     *
//     * @param fId
//     */
//    @Override
//    public ResponseResult<Void> deleteByLogical(@Param("fId") String fId) {
//        String errorMessage;
//        // 验证关联Id的数据合法性
//        LlgDataDikeStructure llgDataDikeStructure = llgDataDikeStructureMapper.selectById(fId);
//        if (llgDataDikeStructure == null) {
//            // NOTE: 修改下面方括号中的话述
//            errorMessage = "数据验证失败，当前 [对象] 并不存在，请刷新后重试！";
//            return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST, errorMessage);
//        }
//        MyModelUtil.fillCommonsForUpdate(llgDataDikeStructure, llgDataDikeStructure);
//        //IotMyModelUtil.fillCommonsForUpdateNotUser(llgDataDikeStructure);
////		llgDataDikeStructure.setDeletedFlag(GlobalDeletedFlag.DELETED);
//        boolean row = this.updateById(llgDataDikeStructure);
//        if (row) {
//            return ResponseResult.success();
//        } else {
//            return ResponseResult.error(ErrorCodeEnum.TRANSACTION_MESSAGE_LOCAL_STATUS_ROLLBACK, "删除失败！");
//        }
//    }
//
//    /**
//     * 根据主键fId更新表llg_data_dike_structure信息
//     *
//     * @param llgDataDikeStructure
//     */
//    @Transactional(rollbackFor = Exception.class)
//    @Override
//    public LlgDataDikeStructure updateData(LlgDataDikeStructure llgDataDikeStructure) {
//
//        LlgDataDikeStructure oldLlgDataDikeStructure = llgDataDikeStructureMapper.selectById(llgDataDikeStructure.getfId());
//        if (oldLlgDataDikeStructure == null) {
//            // NOTE: 修改下面方括号中的话述
//            log.error("LlgDataDikeStructureServiceImpl.updateData request:{},数据不存在。", JSON.toJSONString(llgDataDikeStructure));
//            return null;
//        }
//        MyModelUtil.fillCommonsForUpdate(llgDataDikeStructure, oldLlgDataDikeStructure);
//        //IotMyModelUtil.fillCommonsForUpdateNotUser(llgDataDikeStructure);
//        boolean row = this.updateById(llgDataDikeStructure);
//        if (row) {
//            return llgDataDikeStructure;
//        }
//        return null;
//    }
//
//    /**
//     * 新增表llg_data_dike_structure信息
//     *
//     * @param llgDataDikeStructure
//     */
//    @Transactional(rollbackFor = Exception.class)
//    @Override
//    public LlgDataDikeStructure add(LlgDataDikeStructure llgDataDikeStructure) {
//
//        int row = llgDataDikeStructureMapper.insert(this.buildDefaultValue(llgDataDikeStructure, null));
//        if (0 < row) {
//            return llgDataDikeStructure;
//        }
//        return null;
//    }
//
//    /**
//     * 根据岸别、起始里程桩号，判断薄弱岸段在哪些岸段上
//     * @param side
//     * @param start
//     * @param end
//     * @return
//     */
//    @Override
//    public List<LlgDataDikeStructureVO> likeStructure(String side, String start, String end) {
//        //分割出薄弱岸段起点的 桩号 距离
//        String[] split_start = start.split("\\+");
//        Integer ZH_start = Integer.parseInt(split_start[0]);
//        Integer ZH_start_len = Integer.parseInt(split_start[1]);
//        ArrayList<LlgDataDikeStructureVO> llgDataDikeStructureVOS = new ArrayList<>();
//        LambdaQueryWrapper<LlgDataDikeStructure> queryWrapper = new LambdaQueryWrapper();
//        //根据岸别具体查询 桩号模糊查询
//        queryWrapper.eq(StringUtils.isNotEmpty(side),LlgDataDikeStructure::getSide,side)
//                .likeRight(LlgDataDikeStructure::getMilestone,ZH_start.toString());
//        List<LlgDataDikeStructure> llgDataDikeStructures = llgDataDikeStructureMapper.selectList(queryWrapper);
//        llgDataDikeStructures.stream().forEach( e ->{
//            String milestone = e.getMilestone();
//            String[] split_milestone = milestone.split("\\+");
//            Integer ZH_milestone = Integer.parseInt(split_milestone[0]);
//            Integer ZH_milestone_len = Integer.parseInt(split_milestone[1]);
//            String milestone1 = e.getMilestone1();
//            String[] split_milestone1 = milestone1.split("\\+");
//            Integer ZH_milestone1 = Integer.parseInt(split_milestone1[0]);
//            Integer ZH_milestone1_len = Integer.parseInt(split_milestone1[1]);
//            //当薄弱岸段起始桩号在岸段起始桩号之间时 满足条件
//            if ( ZH_start == ZH_milestone1 && (ZH_start_len > ZH_milestone_len && ZH_start_len < ZH_milestone1_len)){
//                llgDataDikeStructureVOS.add(BeanCopy.copy(e,LlgDataDikeStructureVO.class));
//            } else if (ZH_start < ZH_milestone1 && ZH_start_len > ZH_milestone_len) {
//                llgDataDikeStructureVOS.add(BeanCopy.copy(e,LlgDataDikeStructureVO.class));
//            }
//        });
//        return llgDataDikeStructureVOS;
//    }
//
//    @Override
//    public ResponseResult<Void> batchSave(List<LlgDataDikeStructure> llgDataDikeStructureList) {
//        if (CollectionUtils.isEmpty(llgDataDikeStructureList)) {
//            return ResponseResult.success();
//        }
//        List<String> ids = llgDataDikeStructureList.stream().map(e -> e.getfId()).collect(Collectors.toList());
//        List<String> insertIds = new ArrayList<>();
//        List<String> updateIds = new ArrayList<>();
//        IotMyModelUtil.filterInsertOrUpdateStringId(llgDataDikeStructureMapper, ids, insertIds, updateIds);
//
//        List<LlgDataDikeStructure> insertLlgDataDikeStructure = new ArrayList<>();
//        List<LlgDataDikeStructure> updateLlgDataDikeStructure = new ArrayList<>();
//        for (LlgDataDikeStructure llgDataDikeStructure : llgDataDikeStructureList) {
//            if (null == llgDataDikeStructure.getfId() || insertIds.contains(llgDataDikeStructure.getfId())) {
//                insertLlgDataDikeStructure.add(llgDataDikeStructure);
//            } else if (updateIds.contains(llgDataDikeStructure.getfId())) {
//                updateLlgDataDikeStructure.add(llgDataDikeStructure);
//            }
//        }
//        insertLlgDataDikeStructure = insertLlgDataDikeStructure.stream().map(e -> {
//            e.setfId(String.valueOf(idGenerator.nextLongId()));
//            return this.buildDefaultValue(e, null);
//        }).collect(Collectors.toList());
//        updateLlgDataDikeStructure = updateLlgDataDikeStructure.stream().map(e -> {
//            IotMyModelUtil.fillCommonsForUpdateNotUser(e);
//            return e;
//        }).collect(Collectors.toList());
//
//        this.saveBatch(insertLlgDataDikeStructure);
//        this.updateBatchById(updateLlgDataDikeStructure);
//        return ResponseResult.success();
//    }
//
//    private LlgDataDikeStructure buildDefaultValue(LlgDataDikeStructure newLlgDataDikeStructure, LlgDataDikeStructure oldLlgDataDikeStructure) {
//        if (null == newLlgDataDikeStructure.getfId()) {
//            newLlgDataDikeStructure.setfId(String.valueOf(idGenerator.nextLongId()));
//            //MyModelUtil.fillCommonsForInsert(newLlgDataDikeStructure);
//            IotMyModelUtil.fillCommonsForInsertNotUser(newLlgDataDikeStructure);
//        } else {
//            //MyModelUtil.fillCommonsForUpdate(newLlgDataDikeStructure, oldLlgDataDikeStructure);
//            IotMyModelUtil.fillCommonsForUpdateNotUser(newLlgDataDikeStructure);
//        }
//
////		newLlgDataDikeStructure.setDeletedFlag(GlobalDeletedFlag.NORMAL);
//        return newLlgDataDikeStructure;
//    }
//
//}
